<?php
class Msg extends DB{

	public function getMsgs($userid){
		
		$sql = "SELECT
				 *
				FROM 
				message
				WHERE
				from_id='$userid' 
				OR
				to_id='$userid'
				order by datetime desc";
		
		return parent::fetchAll($sql);
	}
	
	public function addMsgs($from_id,$to_id,$content){
		$sql = "INSERT INTO `message` VALUES (:id,:from_id,:to_id,:content,:datetime)";
		$field = array(':id' => '',
					   ':from_id' => $from_id,
					   ':to_id' => $to_id,
					   ':content' => $content,
					   ':datetime' => date("Y-m-d h:i:s")
					   
					  );	
		return parent::updateDB($sql,$field);			
	}

}
?>